home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / COMMAND2.C < prev    next >
C/C++ Source or Header  |  1991-02-04  |  7KB  |  372 lines

  1. #include "pt.h"
  2. #include "stdlib.h"
  3. #include "time.h"
  4.  
  5. int pascal
  6. /* XTAG:command2 */
  7. command2(fn, c, w)
  8.     int fn;
  9.     unsigned char c;
  10.     register struct window *w;
  11. {
  12.     extern struct window *windowList;
  13.     extern struct window *activeWindow;
  14.     extern unsigned char msgBuffer[];
  15.     extern int debug;
  16.     extern struct window *selWindow;
  17.     extern long selBegin, selEnd;
  18.     extern int copyPending, movePending;
  19.     extern struct window *pendWindow;
  20.     extern long pendPosition;
  21.     extern int searchMode;
  22.     extern int topOnFind;
  23.     extern int scrRows, scrCols;
  24.     extern int lastOnTopline;
  25.     extern int menuRow, menuCol;
  26.     extern int passEvhead;
  27.     extern long passCp;
  28.     extern int i43lines;
  29.     extern int mousePresent;
  30. #ifdef OVERLAYS
  31.     extern int quitExecuted;
  32. #endif
  33.     extern time_t timeOfLastSave;
  34.     extern struct openFile *files;
  35.  
  36.     int row1, col1, row2, col2;
  37.     int n;
  38.     unsigned char *fileName;
  39.     struct window *w2;
  40.  
  41. switch( fn ) {
  42.  
  43. case FMOUSECOM1:
  44. case FMOUSECOM2:
  45.     if( w == NULL )
  46.         break;
  47.     mouseCommand(fn, w, passCp, menuRow, menuCol, passEvhead);
  48.     break;
  49.  
  50. case FSELECT:
  51.     if( w == NULL )
  52.         break;
  53.     if( select(w, passCp, menuRow, menuCol, passEvhead) )
  54.         return 2;
  55.     break;
  56.  
  57. case FEXTEND:
  58.     if( w == NULL )
  59.         break;
  60.     if( extend(w, passCp, menuRow, menuCol, passEvhead) )
  61.         return 2;
  62.     break;
  63.  
  64. case FSAVEALL:
  65.     w2 = windowList;
  66.     while( w2 != NULL ) {
  67.         if( files[w2->fileId].isChanged )
  68.             saveFile(w2);
  69.         w2 = w2->nextWindow;
  70.     }
  71.     timeOfLastSave = time(NULL);
  72.     break;
  73.  
  74. case FHIDE:
  75.     if( w == NULL )
  76.         break;
  77.     hideWindow(w);
  78.     break;
  79.  
  80. case FRESIZE:
  81.     if( w == NULL )
  82.         break;
  83.     if( getBox(0, 0, &row1, &col1, &row2, &col2, 0) == 2 )
  84.         break;
  85.     if( row1 == row2 && col1 == col2 ) {
  86.         row2 = scrRows-1;
  87.         col2 = scrCols-1;
  88.     }
  89.     if( moveWindow(w, row1, col1, row2, col2) != 0 )
  90.         msg("Window change failed", 1);
  91.     break;
  92.  
  93. case FREDO:
  94.     if( w == NULL )
  95.         break;
  96.     redo();
  97.     break;
  98.  
  99. case FUNDO:
  100.     if( w == NULL )
  101.         break;
  102.     undo(1);
  103.     break;
  104.  
  105. case FUNDOBACK:
  106.     if( w == NULL )
  107.         break;
  108.     undo(0);
  109.     break;
  110.  
  111. case FCURLEFT:
  112. case FCURRIGHT:
  113. case FCURUP:
  114. case FCURDOWN:
  115. case FBEGINLINE:
  116. case FENDLINE:
  117. case FLEFTMBUTTON:
  118. case FRIGHTMBUTTON:
  119.     cursor(fn, mousePresent);
  120.     /* only move the cursor if the mouse is present */
  121.     break;
  122.  
  123. case FLOADFILE:
  124.     if( w == NULL )
  125.         doNewWindow(FNEWWINDOW, 0);
  126.     else
  127.         loadWindow(w, fn);
  128.     break;
  129.  
  130. case FEXECCMD:
  131. case FEXECSHELL:
  132.     execCmd(fn);
  133.     break;
  134.  
  135. case FCANCEL:
  136.     if( copyPending ) {
  137.         copyPending = 0;
  138.         msg("", 0);
  139.     }
  140.     if( movePending ) {
  141.         movePending = 0;
  142.         msg("", 0);
  143.     }
  144.     break;
  145.  
  146. case FSEARCH:
  147.     if( w == NULL )
  148.         break;
  149.     if( searchMode == 3 ) {
  150.         w2 = w;    /* start with the current window */
  151.         /* n determines whether to ask */
  152.         n = 0;
  153.         while( w2 != NULL ) {
  154.             if( searchFor(n, w2) )    /* if the string is found */
  155.                 break;    /* then drop out of the loop */
  156.             w2 = w2->nextWindow;
  157.             n = 2;    /* so search uses the last string entered */
  158.         }
  159.         while( w2 != NULL && w2 != windowList )
  160.             /* bottom the top window until the window where */
  161.             /* we found the string is the top window */
  162.             doTopWindow(windowList, 2);
  163.     } else
  164.         searchFor(0, w);
  165.     break;
  166.  
  167. case FREPSEARCH:
  168.     if( w == NULL )
  169.         break;
  170.     if( searchMode == 3 ) {
  171.         w2 = w;    /* start with the current window */
  172.         while( w2 != NULL ) {
  173.             if( searchFor(1, w2) )    /* if the string is found */
  174.                 break;    /* then drop out of the loop */
  175.             w2 = w2->nextWindow;
  176.         }
  177.         while( w2 != NULL && w2 != windowList )
  178.             /* bottom the top window until the window where */
  179.             /* we found the string is the top window */
  180.             doTopWindow(windowList, 2);
  181.     } else
  182.         searchFor(1, w);
  183.     break;
  184.  
  185. case FREPLACE:
  186.     if( w == NULL )
  187.         break;
  188.     replaceText(w);
  189.     break;
  190.  
  191. case FASCII:
  192.     if( selWindow == NULL )
  193.         break;
  194.     insAscii();
  195.     break;
  196.  
  197. case FCHARACTER:
  198.     if( selWindow == NULL )
  199.         break;
  200.     insChar(c, 1);
  201.     break;
  202.  
  203. case FCOPY:
  204.     if( selWindow == NULL )
  205.         break;
  206.     if( copyPending ) {
  207.         copyMove(selWindow, selBegin, selEnd,
  208.             pendWindow, pendPosition, COPY);
  209.         copyPending = 0;
  210.         msg("", 0);
  211.     } else {
  212.         msg("Duplicate mode", 4);
  213.         copyPending = 1;
  214.         pendWindow = selWindow;
  215.         pendPosition = selBegin;
  216.     }
  217.     break;
  218.  
  219. case FMOVE:
  220.     if( selWindow == NULL )
  221.         break;
  222.     if( movePending ) {
  223.         copyMove(selWindow, selBegin, selEnd,
  224.             pendWindow, pendPosition, MOVE);
  225.         movePending = 0;
  226.         msg("", 0);
  227.     } else {
  228.         msg("Extract mode", 4);
  229.         movePending = 1;
  230.         pendWindow = selWindow;
  231.         pendPosition = selBegin;
  232.     }
  233.     break;
  234.  
  235. case FDELETE:
  236.     if( selWindow == NULL )
  237.         break;
  238.     deleteChars(selWindow->fileId, UPDATEWINDOWS, 1);
  239.     break;
  240.  
  241. case FDELNOSCRAP:
  242.     if( selWindow == NULL )
  243.         break;
  244.     deleteChars(selWindow->fileId, UPDATEWINDOWS, 0);
  245.     break;
  246.  
  247. case FQUITNOSAVE:
  248.     if( quitPoint(fn, 1) ) {
  249. #ifdef OVERLAYS
  250.         quitExecuted = 1;
  251. #endif
  252.         return 1;
  253.     }
  254.     break;
  255.  
  256. case FQUITASK:
  257. case FQUITSAVE:
  258.     if( quitPoint(fn, 0) ) {
  259. #ifdef OVERLAYS
  260.         quitExecuted = 1;
  261. #endif
  262.         return 1;
  263.     }
  264.     break;
  265.  
  266. case FDEBUG:
  267.     sprintf(msgBuffer, "%d", debug);
  268.     fileName = getInput("debug=", msgBuffer, 0);
  269.     debug = atoi(fileName);
  270.     break;
  271.  
  272. case FINFORM:
  273.     doInform();
  274.     break;
  275.  
  276. case FNEWWINDOW:
  277.     doNewWindow(fn, 0);
  278.     break;
  279.  
  280. case FWRITEFILE:
  281.     if( w == NULL )
  282.         break;
  283.     writeFile(w);
  284.     break;
  285.  
  286. case FTOPFILE:
  287.     if( w == NULL )
  288.         break;
  289.     /* remember where we came from */
  290.     w->rowLastline = w->numTopline;
  291.     w->posTopline = 0;
  292.     w->numTopline = 1;
  293.     w->indent = 0;
  294.     redrawWindow(w);
  295.     break;
  296.  
  297. case FBOTFILE:
  298.     if( w == NULL )
  299.         break;
  300.     bottomFile(w);
  301.     break;
  302.  
  303. case FREDRAW:
  304.     redrawBox(0, 0, scrRows-1, scrCols-1);
  305.     updateScreen(0, scrRows-1);
  306.     break;
  307.  
  308. case FZOOM:
  309.     if( w == NULL )
  310.         break;
  311.     zoomWindow(w);
  312.     break;
  313.  
  314. case FTOP:
  315.     if( w == NULL )
  316.         break;
  317.     doTopWindow(w, 0);
  318.     break;
  319.  
  320. case FTOPBOTTOM:
  321.     if( w == NULL )
  322.         break;
  323.     doTopWindow(w, 1);
  324.     break;
  325.  
  326. case FBOTTOM:
  327.     if( w == NULL )
  328.         break;
  329.     doTopWindow(w, 2);
  330.     break;
  331.  
  332. case FPGUP:
  333.     if( w == NULL )
  334.         break;
  335.     /* set up the screen map and scroll the window */
  336.     setMap(w->row1, w->col1, w->row2, w->col2, 1, 0x07);
  337.     maskTop(w);
  338.     downScroll(w, w->row2 - w->row1 - 3);
  339.     break;
  340.  
  341. case FPGDN:
  342.     if( w == NULL )
  343.         break;
  344.     /* set up the screen map and scroll the window */
  345.     setMap(w->row1, w->col1, w->row2, w->col2, 1, 0x07);
  346.     maskTop(w);
  347.     upScroll(w, w->row2 - w->row1 - 3);
  348.     break;
  349.  
  350. case FGOTO:
  351.     if( w == NULL )
  352.         break;
  353.     doGoto(w, -1);
  354.     break;
  355.  
  356. case FCLOSEWINDOW:
  357.     if( w == NULL )
  358.         break;
  359.     closeWindow(w, 1, 1);
  360.     break;
  361.  
  362. case FDONOTHING:
  363. case 0:
  364.     break;
  365.  
  366. default:
  367.     msg("No action is defined for that key [Alt-h for HELP]", 1);
  368.     break;
  369. }
  370. return 0;
  371. }
  372.